﻿<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="SelectDepartmentMulti.aspx.vb" Inherits="PubProject.SelectDepartmentMulti" %>
<%@ Register TagPrefix="cnt" Namespace="Mysoft.Map.Application.Controls" Assembly="Mysoft.Map.Application.Components" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head runat="server">
	<title>部门列表</title>
	<!-- Global -->
	<link rel="stylesheet" type="text/css" href="/_common/styles/global.css" />
	<script type="text/javascript" src="/_common/scripts/global.js"></script>
	<!-- Tree -->
	<link rel="stylesheet" type="text/css" href="/_controls/tree/tree.css" />
	<!-- Menu -->
	<link rel="stylesheet" type="text/css" href="/_nav/menu.css" />
	<script type="text/javascript" src="/_nav/menu.js"></script>
	<!-- Grid -->
	<link rel="stylesheet" type="text/css" href="/_grid/map_grid.css" />
	<!-- Form -->
	<link rel="stylesheet" type="text/css" href="/_forms/styles/form.css" />
	<!-- Tab -->
	<link rel="stylesheet" type="text/css" href="/_nav/tabs.css" />
	<!-- Utility-->
	<script type="text/javascript" src="/_controls/util/util.js"></script>
	<!-- Public -->
	<script type="text/javascript" src="/PubProject/JS/Public.js"></script>
	<script type="text/javascript" src="/Xmjd/JS/Public.js"></script>
	<style>
		.scrollColThead {

		position: relative; 

		top: expression(this.parentElement.parentElement.parentElement.scrollTop);

		z-index:2;

		}
	</style>
	<script type="text/javascript">
	    function windows_load() {
	    //初始化窗体
	    if (window.dialogArguments != undefined && window.dialogArguments != "") {
	        var strDeptGUIDList = window.dialogArguments;
	            //循环勾选已选种的部门
	        var TableLength = document.all("Table1").rows.length;
	            for (var i = 0; i < TableLength; i++) {
	                var arrDepts = strDeptGUIDList.split(";");
	                for (var j = 0; j < arrDepts.length; j++) {
	                    var strdeptGUID = document.all("Table1").rows(i).attributes("value").value;
	                    if (strdeptGUID == arrDepts[j]) {
	                        //设置为选种
	                        document.all("Table1").rows(i).cells(0).childNodes(2).childNodes(0).checked = true;
	                    }
	                }
	            }
	        }

	    }

	    // 确定返回
	    // 返回类别名称和代码
	    function okClick() {
	        var arrTr = getSelectedValue();
//	        if (arrTr[0] == undefined || arrTr[0] == "") {
//	            alert("请先选择部门！");
//	            return;
//	        }
	        parent.window.returnValue = arrTr;
	        parent.window.close();
	    }

	    // 获取复选框的值
	    function getSelectedValue() {
	        var iCount = 0;
	        var arrRtn = new Array(3);

	        arrRtn[0] = new Array();
	        arrRtn[1] = new Array();
	        arrRtn[2] = new Array();
	        // 部门GUID,部门代码,部门名称
	        for (var i = 1; i < Table1.rows.length; i++)		// 不考虑“所有类别”行
	        {
	            if (Table1.rows[i].butype == "1") {
	                if (Table1.rows[i].cells[0].children[2].children[0].checked == true) {
	                    arrRtn[0][iCount] = Table1.rows[i].value; 				// 部门GUID
	                    arrRtn[1][iCount] = Table1.rows[i].code; 		        // 部门代码
	                    arrRtn[2][iCount] = Table1.rows[i].text; 		        // 部门名称
	                    iCount++;
	                }
	            }
	        }
            //全部未选中，给空值
	        if (iCount == 0) {
	            arrRtn[0][0] = "";
	            arrRtn[1][0] = "";
	            arrRtn[2][0] = "";
	        }

	        return arrRtn;
	    }

	    //选取一个部门，则其所有层级关系的上级部门全部选中，其所有下级部门也全部选中
	    //取消选取一个部门，则其上级部门不变，取消选中其所有下级部门
	    function selectNode(o) {

	        //event.cancelBubble = true;
	        var irowCount, sCode;

	        var sSelectCode = o.parentElement.parentElement.parentElement.code + "."

	        irowCount = Table1.rows.length;

	        //选中
	        if (o.checked) {
	            for (var i = 0; i < irowCount; i++) {
	                sCode = Table1.rows[i].code + ".";
	                //选中所有下级
	                if (sCode.indexOf(sSelectCode) == 0) {
	                    Table1.rows[i].cells[0].children[2].children[0].checked = true;
	                }
	            }
	        }
	        //取消选中
	        else {
	            for (var i = 0; i < irowCount; i++) {
	                sCode = Table1.rows[i].code + ".";
	                //取消选中所有下级
	                if (sCode.indexOf(sSelectCode) == 0) {
	                    Table1.rows[i].cells[0].children[2].children[0].checked = false;
	                }
	            }
	        }
	    }
	</script>
</head>
<body MS_POSITIONING="GridLayout" onload="windows_load()">
	<form id="Form1" runat="server">
		<asp:textbox id="txtCreateBUCode" style="DISPLAY: none" Runat="server"></asp:textbox>
		<asp:textbox id="txtCreateBUName" style="DISPLAY: none" Runat="server"></asp:textbox>
		<asp:textbox id="txtDeptList" style="DISPLAY: none" Runat="server"></asp:textbox>
		<table style="FONT-SIZE: 9pt" height="100%" cellSpacing="0" cellPadding="0" width="100%">
			<tr>
				<td valign="top">
					<table width="100%" cellspacing="0" cellpadding="0" height="100%">
				<tr>
					<td class="main">
						<table width="100%" cellspacing="0" cellpadding="0" height="100%" style="table-layout:fixed">
							<colgroup>
								<col>
								<col width="45">
							</colgroup>
							<TBODY>
								<tr height="20">
									<td><b style="COLOR:#666666">部门列表</b></td>
									<td></td>
								</tr>
								<tr height="10">
									<td colspan="2">
									</td>
								</tr>
								<tr>
									<td colspan="2" class="wizBox1">
										<DIV style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; OVERFLOW: auto; WIDTH: 320; PADDING-TOP: 5px; HEIGHT: 100%">
											<cnt:repeater id="repCompany" runat="server" SortSignDESC='<img src="/_imgs/ico_arrow_d.gif">' SortSignASC='<img src="/_imgs/ico_arrow_u.gif">'
												PKField="BldCode" LinkAlign="right" LinkCssClass="a1" FooterCssClass="footer" EnablePager="false">
												<HeaderTemplate>
													<TABLE id="Table1" cellspacing="0" cellpadding="0" width="100%" class="singleSelectTree" ismultiselect="1"  defaultShowLevel="5">
												</HeaderTemplate>
												<ItemTemplate>
													<tr height='20' code='<%# DataBinder.Eval(Container, "DataItem.code") %>'
																	value='<%# DataBinder.Eval(Container, "DataItem.guid") %>'
																	text='<%# DataBinder.Eval(Container, "DataItem.name") %>'	
																	butype='<%# DataBinder.Eval(Container, "DataItem.butype") %>'																
																	allowselect='0'
																	is_hide="false" onclick="Table1.clickNode(this)"
																	onmouseover='this.bgColor="#E3E9F4"' onmouseout='this.bgColor="#ffffff"'>
														<td>
															<span></span><label style="CURSOR: hand;"></label>
															<asp:CheckBox id="chkSelect" runat="server" onclick="selectNode(this)"  style="width:20px;" Text="" Checked='<%# iif(DataBinder.Eval(Container, "DataItem.checked")="1","true","false") %>' Visible='<%# iif(DataBinder.Eval(Container, "DataItem.butype")="0","false","true") %>'></asp:CheckBox>
															<%# DataBinder.Eval(Container, "DataItem.name") %>															
															<input id="txtIfEnd" style="display:none;" runat="server" value='<%# DataBinder.Eval(Container, "DataItem.butype") %>'  NAME="txtIfEnd">
														</td>
													</tr>
												</ItemTemplate>
												<FooterTemplate>
						</table>
						</FooterTemplate> </cnt:repeater></DIV>
					</td>
				</tr>
			</table>
				</td>
			</tr>			
			<tr height="40">
				<td class="buttons">
					<button onclick="okClick()" id="btnOk" type="button">确 定</button>&nbsp;&nbsp;
					<button onclick="parent.window.close();" type="button">取 消</button>
				</td>
			</tr>
			
		</table>
		</form>
</body>
</html>
